﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace trackIRDLL
{
    public interface ASignatures
    {

    }

    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class ActiveX : ASignatures
    {
        [DllImport("TrackIR.dll", EntryPoint="tirSetupCamera")]
        public static extern void tirSetupCamera_();
        [DllImport("TrackIR.dll", EntryPoint="tirShutdownCamera")]
        public static extern void tirShutdownCamera_();
        [DllImport("TrackIR.dll", EntryPoint="tirIsCameraInitialized")]
        public static extern bool tirIsCameraInitialized_();
        [DllImport("TrackIR.dll", EntryPoint="tirStartCamera")]
        public static extern void tirStartCamera_();
        [DllImport("TrackIR.dll", EntryPoint="tirStopCamera")]
        public static extern void tirStopCamera_();
        [DllImport("TrackIR.dll", EntryPoint="tirIsCameraRunning")]
        public static extern bool tirIsCameraRunning_();
        [DllImport("TrackIR.dll", EntryPoint="tirRecenter")]
        public static extern void tirRecenter_();
        [DllImport("TrackIR.dll", EntryPoint="tirGetMatrix")]
        public static extern void tirGetMatrix_(float[] matrixItem);

        static ActiveX() {
            tirSetupCamera_();
            tirStartCamera_();
        }

        public float[] matrixItem = { 0.0f, 0.0f, 0.0f, 0.0f,
                                      0.0f, 0.0f, 0.0f, 0.0f,
                                      0.0f, 0.0f, 0.0f, 0.0f,
                                      0.0f, 0.0f, 0.0f, 0.0f,
                                    };

        public string tirGetMatrix()
        {
            string strFloat = "";
            if (tirIsCameraRunning_() == true)
            {
                tirGetMatrix_(matrixItem);
                for (int i = 0; i < matrixItem.Length; i++)
                {
                    strFloat += matrixItem[i].ToString() + ",";
                }
            }
            return strFloat;
        }

        public bool tirIsCameraInitialized()
        {
            return tirIsCameraInitialized_();
        }
        public bool tirIsCameraRunning()
        {
            return tirIsCameraRunning_();
        }
        public void tirRecenter()
        {
            tirRecenter_();
        }

        ~ActiveX() {
            tirStopCamera_();
            tirShutdownCamera_();
        }
    }
}
